/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>服务项目管理</el-breadcrumb-item>
    </el-breadcrumb>

<br>
<br>

<el-form :model="userFrom" :rules="rules" ref="userFrom" label-width="100px" class="demo-userFrom">
        <el-form-item label="一级服务" prop="firstName"  >
          <el-select v-model="userFrom.firstId" placeholder="请选择 "  @change="secondServe(userFrom.firstId)">
              <el-option
              v-for="item in options"
              :key="item.firstId"
              :label="item.firstName"
              :value="item.firstId"
             
             >
           </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="二级服务" prop="secondName">
          <el-select v-model="userFrom.secondId" placeholder="请选择">
            <el-option
              v-for="item in optionss"
              :key="item.secondId"
              :label="item.secondName"
              :value="item.secondId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="三级服务" prop="thirdName">
          <el-select v-model="userFrom.thirdId" placeholder="请选择">
            <el-option
              v-for="item in optionsss"
              :key="item.thirdId"
              :label="item.thirdName"
              :value="item.thirdId">
            </el-option>
          </el-select>
        </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="fabu(userFrom)">发布</el-button>
      </el-form-item>

</el-form>


    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>

      <el-table-column sortable prop="firstServe" label="服务" width="100">
      </el-table-column>

        <el-table-column sortable prop="flag" label="上架状态" width="150">

        <template slot-scope="scope">
          <el-switch disabled v-model="scope.row.flag==1?nshow:fshow" active-color="#13ce66" inactive-color="#ff4949" @change="editType(scope.$index, scope.row)">
          </el-switch>
        </template>

      </el-table-column>

      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="serveManagement(scope.$index, scope.row)"
            >上下架管理</el-button
          >
        </template>
      </el-table-column>
    </el-table>

<h1>服务项目的数据统计</h1>
上架服务数量：{{quantityServe.s}}
<br>
下架服务数量：{{quantityServe.x}}


  </div>
</template>

<script>
import * as service from "@/api/service.js";
import axios from "axios";
export default {
  //model
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: "添加",
      userFrom: {
        firstId:"",
        secondId:"",
        thirdId:"",
        firstName:"",
        secondName:"",
        thirdName:"",
      },
      // rules表单验证
      rules: {
        // deptName: [
        //   { required: true, message: '请输入部门名称', trigger: 'blur' }
        //  ],
        //  deptNo: [{ required: true, message: '请输入部门代码', trigger: 'blur' }]
      },
      formInline: {
        page: 1,
        limit: 5,
        usermannge: {
          firstName:"",
          secondName:"",
          thirdName:"",
        },
      },

      quantityServe:{
        s:"",
        x:"",
      },

      // 删除部门
      seletedata: {
        ids: "",
        token: localStorage.getItem("logintoken"),
      },
      list:[],
      userparm: [], //搜索权限
      listData: [], //用户数据

      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 5,
        total: 10,
      },

      storeId:"",
      //下拉框属性
      options: [],
      optionss:[],
      optionsss:[],
      value: "",
    };
  },
  // 注册组件
  components: {

  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.first();
    this.third();
    this.selectServe();
    this.countServe();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {

    // selects() {
    //   axios
    //     .get("/role/selects")
    //     .then((res) => {
    //       console.log("!!!!!!!!!!!!!!!!!!!"+res);
    //       this.options = res.data;

    //     });
    // },
  first(){
    service.first()
      .then((res) =>{
        console.log(res.data.data);
        this.options = res.data.data;
      }) 
  },
  secondServe(id){
    axios.get("http://localhost:9000/ses/mdStorefirst/secondServe/"+id)
     .then((res) => {
          console.log("1111111111111111",res.data);
          this.optionss = res.data;
         this.userFrom.secondId=""
        });
  },
 
  third(){
    service.third()
      .then((res) =>{
        console.log(res.data.data);
        this.optionsss = res.data.data;
      }) 
  },

  fabu(userFrom){
    this.storeId = sessionStorage.getItem("storeId");
    service.fabu(userFrom,this.storeId)
        .then((res)=>{
          console.log(res.data.code)
          if(res.data.code==500){
              this.$message({
              type: "success",
              message: "服务已存在！",
            }); 
          }else{
              this.$message({
              type: "success",
              message: "发布成功",
          });  
          }
          this.selectServe(); 
          this.countServe();
      })
  },

  selectServe(){
    this.storeId = sessionStorage.getItem("storeId");
    service.selectServe(this.storeId)
        .then((res)=>{
          console.log("xxxx"+res.data.data)
          this.listData=res.data.data   
        })
  },

  serveManagement(index,row){
    if(row.flag==0){
      row.flag=1
    }else{
      row.flag=0
    }
    service.serveManagement(row)
      .then((res)=>{
        this.selectServe();
        this.countServe();
      })
  },

  countServe(){
    this.storeId = sessionStorage.getItem("storeId");
    service.count(this.storeId)
      .then((res)=>{
        console.log("aaa"+res.data.data.quantityOnShelves)
        this.quantityServe.s=res.data.data.quantityOnShelves;
        this.quantityServe.x=res.data.data.quantityOffTheShelf;
      })
  },



    getDate() {
      axios
        .get("/usermannge/selectAll", {
          params: {
            startpage: this.formInline.page,
            pagesize: this.formInline.limit,
          },
        })
        .then((res) => {
          console.log("1111111111111111",res.data);
          this.listData = res.data.list;
          this.pageparm.total = res.data.total;
          console.log(this.pageparm);
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.limit = parm.pageSize;
      this.search();
    },
    // 搜索事件
    search() {
      axios
        .post("/usermannge/search", this.formInline)
        .then((res) => {
          console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",res.data);
          this.listData = res.data.list;
          this.pageparm.total = res.data.total;
          console.log(this.pageparm);
        })
        .catch((res) => {});
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      if (row != undefined && row != "undefined") {
        this.title = "修改";
        this.userFrom.customerId = row.customerId;
        this.userFrom.customerInickname = row.customerInickname;
        this.userFrom.customerPhonenumber = row.customerPhonenumber;
        this.userFrom.customerType = row.customerType;
        this.userFrom.customerEmail = row.customerEmail;
        this.userFrom.customerIcreater = row.customerIcreater;
        this.userFrom.customerIcreattime = row.customerIcreattime;
        this.userFrom.customerIeditor = row.customerIeditor;
        this.userFrom.customerIedittime = row.customerIedittime;
      } else {
        this.title = "添加";
        this.userFrom.customerId = "";
        this.userFrom.customerInickname = "";
        this.userFrom.customerPhonenumber = "";
        this.userFrom.customerType = "";
        this.userFrom.customerEmail = "";
        this.userFrom.customerIcreater = "";
        this.userFrom.customerIcreattime = "";
        this.userFrom.customerIeditor = "";
        this.userFrom.customerIedittime = "";
      }
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate((valid) => {
        if (valid) {
          //下面这个是 系统封装好的接口方法!
          // deptSave(this.userFrom)
          if (this.title == "添加") {
            axios
              .post("/usermannge/insert", this.userFrom)
              .then((res) => {
                this.editFormVisible = false;
                this.loading = false; //加载状态
                // this.getdata(this.formInline)

                this.$message({
                  type: "success",
                  message: "新增用户保存成功！",
                });
                this.getDate();
              })
              .catch((err) => {
                this.editFormVisible = false;
                this.loading = false;
                this.$message.error("用户保存失败，请稍后再试！");
              });
          } else if (this.title == "修改") {
            axios
              .post("/usermannge/update", this.userFrom)
              .then((res) => {
                this.editFormVisible = false;
                this.loading = false; //加载状态
                // this.getdata(this.formInline)
                this.$message({
                  type: "success",
                  message: "用户账户成功！",
                });
                this.getDate();
              })
              .catch((err) => {
                this.editFormVisible = false;
                this.loading = false;
                this.$message.error("用户账户失败，请稍后再试！");
              });
          }
        }
      });
    },
    // 删除角色
    deleteUser(index, row) {
      this.$confirm("确定要删除吗?", "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          console.log(index, "-------------", row);
          console.log(axios);
          //这个是restful风格
          axios
            .post("/usermannge/delete/" + row.customerId, {
              //传的对象
            })
            .then((res) => {
              this.$message({
                type: "success",
                message: "用户已删除!",
              });
              this.getDate();
            })
            .catch((err) => {
              this.loading = false;
              this.$message.error("用户删除失败，请稍后再试！");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 